package com.sczmgk.hotline_pzh.ui;

import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.google.gson.Gson;
import com.linkrenhe.frame.http.Tools;
import com.sczmgk.hotline_pzh.MyApp;
import com.sczmgk.hotline_pzh.R;
import com.sczmgk.hotline_pzh.base.BaseActivity;
import com.sczmgk.hotline_pzh.callback.SimplePaserJsonCallback;
import com.sczmgk.hotline_pzh.constants.Constants;
import com.sczmgk.hotline_pzh.entity.OpinionBean;
import com.sczmgk.hotline_pzh.httputils.MyHttp;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2016/12/12 0012.
 */
public class ProtocolActivity extends BaseActivity{

    /*协议内容*/
    private TextView mTvProtocol;

    /*接受并同意*/
    private Button mBtnAccess;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_protocol);

        setHeader();

        initView();

        initData();

        setListener() ;
    }

    /**
     * 设置标题栏
     */
    private void setHeader() {
        setTitle(R.string.regist_protocol_title);
        setLeftBtnVisibility(View.VISIBLE);
    }

    /**
     * 初始化控件
     */
    private void initView() {
        mTvProtocol = (TextView) findViewById(R.id.tv_protocol);
        mBtnAccess = (Button) findViewById(R.id.btn_protocol);
    }

    /**
     * 初始化数据
     */
    private void initData() {

        Map<String,Object> maps = new HashMap<>();
        maps.put("imei", MyApp.imei);
        MyHttp.requestByCommon(Constants.BASE_URL + Constants.GET_REGISTRATION_AGREEMENT, maps, MyHttp.GET, ProtocolActivity.this, true, null, new SimplePaserJsonCallback() {
            @Override
            public void onVerifyIsNull() {

            }

            @Override
            public void onVerifySuccess(String dataRaw, boolean isCache) {
                Gson gson = new Gson();
                final OpinionBean opinionBean = gson.fromJson(dataRaw, OpinionBean.class);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if(!Tools.isEmpty(opinionBean.content)){

                            mTvProtocol.setText(opinionBean.content);
                        }
                    }
                });
            }
        });
    }

    /**
     * 设置监听
     */
    private void setListener() {

        //接受并同意的点击事件
        mBtnAccess.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setResult(RESULT_OK);
                finish();
            }
        });
    }

    @Override
    public void handleMessage(Message msg) {

    }

    @Override
    public boolean getIsNeedLogin() {
        return false;
    }
}
